﻿namespace HuaWei
{
    using HuaWei.DAI;
    using System;
    using System.Data;

    public class InvokeManager
    {
        private IDataAccess _ida;

        public InvokeManager()
        {
        }

        private bool CheckServiceTime()
        {
            SysManager.WriteLog("请求客户端：" + SysManager.GetClientIP());
            DateTime time = new DateTime(0x7df, 7, 0x1f);
            if (DateTime.Now > time)
            {
                SysManager.WriteLog("**无效请求，请与开发商联系");
                return false;
            }
            return true;
        }

        public DataSet GetDs(DataSet dsSource, string invokeCode, string param)
        {
            //if (this.CheckServiceTime())
            //{
                try
                {
                    if (invokeCode.Equals("GetUpdateData"))
                    {
                        return BusinessTrans.GetInstance(this._ida).GetUpdateData(dsSource, param);
                    }
                    if (invokeCode.Equals("GetXMJBXX"))
                    {
                        return BusinessTrans.GetInstance(this._ida).method2();
                    }
                    if (invokeCode.Equals("GetAllData"))
                    {
                        return BusinessTrans.GetInstance(this._ida).GetAllData(dsSource, param);
                    }
                    if (invokeCode.Equals("CheckUser"))
                    {
                        return BusinessTrans.GetInstance(this._ida).CheckUser(param);
                    }
                    return null;
                }
                catch (Exception exception)
                {
                    SysManager.WriteLog(exception.Message);
                    return null;
                }
            //}
            //return null;
        }

        public string Invoke(DataSet dsSource, string invokeCode, string param)
        {
            SysManager.WriteLog("请求：" + invokeCode);
            //if (this.CheckServiceTime())
            //{
                try
                {
                    if (invokeCode.Equals("Test"))
                    {
                        return ("Test" + DateTime.Now.Date.ToLocalTime());
                    }
                    if (invokeCode.Equals("UpdateJLData"))
                    {
                        return BusinessTrans.GetInstance(this._ida).UpdateJLData(dsSource, param);
                    }
                    if (invokeCode.Equals("UpdateXMData"))
                    {
                        return BusinessTrans.GetInstance(this._ida).UpdateXMData(dsSource, param);
                    }
                    if (invokeCode.Equals("CancelUpdate"))
                    {
                        return BusinessTrans.GetInstance(this._ida).CancelUpdate(param);
                    }
                    if (invokeCode.Equals("RobackDataValidate"))
                    {
                        return BusinessTrans.GetInstance(this._ida).RobackDataValidate(param);
                    }
                    if (invokeCode.Equals("RobackData"))
                    {
                        return BusinessTrans.GetInstance(this._ida).RobackData(param);
                    }
                    if (invokeCode.Equals("ModifyUpdateStatus"))
                    {
                        return BusinessTrans.GetInstance(this._ida).ModifyUpdateStatus(param);
                    }
                    if (invokeCode.Equals("UnLock"))
                    {
                        return BusinessTrans.GetInstance(this._ida).UnLock(param);
                    }
                    return "";
                }
                catch (Exception exception)
                {
                    Log.Write(exception.Message);
                    return ("ERROR: " + exception.Message);
                }
            //}
            //return "ERROR: 访问服务器出错：Server time is null!";
        }

        public IDataAccess SetIDA(IDataAccess ida)
        {
            this._ida = ida;
            return this._ida;
        }
    }
}

